﻿
// 在页面上插入代码
const script = document.createElement('script');
script.setAttribute('type', 'text/javascript');
script.setAttribute('src', chrome.extension.getURL('pageScripts/main.js'));
document.documentElement.appendChild(script);
//发送请求
script.addEventListener('load', (event) => {
  console.log(event);
  postMessage({});
});


// 接收pageScript传来的信息
window.addEventListener("pageScript", function (event) {
  let userInvoiceList = event.detail.userInvoiceList;
  console.log(userInvoiceList);
  var table = $(".We7-Invoiceexact1:eq(1)");
  console.log(table);

  var html = "";

  html += "	<div class=\"We7-Invoiceexact1\" style=\"padding-top: 0px; margin-bottom: 10px;\">";
  html += "		<div class=\"TabsHeader\">";
  html += "			<div style=\"width: 14.2%;\">发票金额<\/div>";
  html += "			<div style=\"width: 14.2%;\">申请时间<\/div>";
  // html += "			<div style=\"width: 14.2%;\">发票类型<\/div>";
  html += "			<div style=\"width: 14.2%;\">发票抬头<\/div>";
  html += "			<div style=\"width: 14.2%;\">登记证号<\/div>";
  html += "			<div style=\"width: 14.2%;\">状态<\/div>";
  html += "			<div style=\"width: 14.2%;\">操作<\/div>";
  html += "			<div style=\"width: 14.2%;\">上传<\/div>";
  html += "		<\/div>";
  for (let index = 0; index < userInvoiceList.length; index++) {
    const item = userInvoiceList[index];
    html += "		<div class=\"TabsContent\">";
    html += "			<div class=\"Header\">";
    html += "				<p style=\"margin-left: 20px;\">买家：" + item.buyer_name + "<\/p>";
    html += "				<p style=\"margin-left: 60px;\">联系QQ：" + item.qq + "<\/p>";
    html += "				<p style=\"margin-left: 60px;\">订单编号：";
    html += "					<div style=\"margin: 0px 5px;\"  data-clipboard-text=\"" + item.invoice_orders[0].order.sn + "\" >" + item.invoice_orders[0].order.sn + "<\/div>";
    html += "				<\/p>";
    html += "			<\/div>";
    html += "			<div class=\"Content\">";
    html += "				<div style=\"width: 14.2%;\" data-clipboard-text=\"" + item.amount + "\">￥" + item.amount + "<\/div>";
    html += "				<div style=\"width: 14.2%;\">" + item.createtime + "<\/div>";
    // html += "				<div style=\"width: 14.2%;\">增值税普通发票<\/div>";
    html += "				<div style=\"width: 14.2%;\" data-clipboard-text=\"" + item.title + "\">" + item.title + "<\/div>";
    html += "				<div style=\"width: 14.2%;\" data-clipboard-text=\"" + item.tax_reg_number + "\">" + item.tax_reg_number + "<\/div>";
    html += "				<div style=\"width: 14.2%;\">" + item.status_text + "<\/div>";
    html += "				<div style=\"width: 14.2%;\">";
    html += "					<a  target=\"_blank\" href=\"https://dev.w7.cc/UserInvoice/" + item.id + "/details\" type=\"button\" class=\"el-button el-button--text\">";
    html += "						<span>新窗口打开<\/span>";
    html += "					<\/a>";
    html += "				<\/div>";
    html += "				<div style=\"width: 14.2%;\">";
    html += "					<a  target=\"_blank\" onclick=\"window.open('https://dev.w7.cc/UserInvoice/" + item.id + "/details', 'newwindow', 'width=632,height=388,toolbar=no, status=no, menubar=no, resizable=yes, scrollbars=yes')\" href=\"javascript:;\" type=\"button\" class=\"el-button el-button--text\">";
    html += "						<span>上传发票<\/span>";
    html += "					<\/a>";
    html += "				<\/div>";
    html += "			<\/div>";
    html += "		<\/div>";
  }
  html += "	<\/div>";

  var clipboard = new ClipboardJS('.TabsContent div');
  clipboard.on('success', function (e) {
    VtMessage.success({
      duration: 3000,
      content: '复制成功',
      offset: 'vt-top-center vt-fixed'
    });
  });
  $(".We7-Invoiceexact1:eq(1)").replaceWith(html);
  $("div[data-clipboard-text]").css({ "color": "red", "cursor": "pointer" });
}, false);